<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>数组1</title>
		<script>
			let arr = [1, 3, 4, 7, 12]
			// 求和
			let sum = 0
			for(let i = 0; i < arr.length; i ++) { // 0 - 4
				// 循环的是数组的索引，每次循环都根据索引获取了数组元素
				sum += arr[i]
			}
			console.log("求和的结果：" + sum)
			/* foreach方法执行循环 */
			let total = 0
			/* arr.forEach((item, index) => {
				total += item
			}) */
			// 等同于
			arr.forEach(item => total += item)
			console.log("求和的结果：" + total)
		</script>
	</head>
	<body>
	</body>
</html>